home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / clients / xmag / cutpaste.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-12  |  4.4 KB  |  170 lines

  1. /*
  2.  * $XConsortium: CutPaste.c,v 1.3 91/07/19 18:29:10 dave Exp $
  3.  *
  4.  * Copyright 1989 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Davor Matic, MIT X Consortium
  24.  */
  25.  
  26. #include <stdio.h>
  27. #include <X11/Xatom.h>
  28. #ifdef MSDOS
  29. #include "X11/IntrinsP.h"      /* QDK 05/17/1994  4:19pm. */
  30. #else
  31. #include "X11/IntrinsicP.h"
  32. #endif
  33. #include "ScaleP.h"
  34. #include "Scale.h"
  35.  
  36. #define XtStrlen(s) ((s) ? strlen(s) : 0)
  37.  
  38. extern Pixmap SWGetPixmap();
  39.  
  40. /* ARGSUSED */
  41. Boolean ConvertSelection(w, selection, target, type, vret, length, format)
  42.     Widget w;
  43.     Atom *selection, *target, *type;
  44.     XtPointer *vret;
  45.     unsigned long *length;
  46.     int *format;
  47. {
  48.     caddr_t *value = (caddr_t *)vret;
  49.     ScaleWidget sw = (ScaleWidget) w;
  50.     Pixmap *pixmap;
  51.  
  52.     switch (*target) {
  53. /*
  54.     case XA_TARGETS:
  55.     *type = XA_ATOM;
  56.     *value = (caddr_t) scaleClassRec.scale_class.targets;
  57.     *length = scaleClassRec.scale_class.num_targets;
  58.     *format = 32;
  59.     return True;
  60. */
  61.  
  62.     case XA_PIXMAP:
  63.     case XA_BITMAP:
  64.     pixmap = (Pixmap *) XtMalloc(sizeof(Pixmap));
  65.     *pixmap = XCreatePixmap(XtDisplay(w), XtWindow(w),
  66.                 sw->scale.image->width, 
  67.                 sw->scale.image->height, 
  68.                 sw->scale.image->depth);
  69.     XPutImage(XtDisplay(w), *pixmap, sw->scale.gc, sw->scale.image,
  70.           0, 0, 0, 0, sw->scale.image->width, sw->scale.image->height);
  71.     *type = XA_PIXMAP;
  72.     *value = (caddr_t) pixmap;
  73.     *length = 1;
  74.     *format = 32;
  75.     return True;
  76.     
  77.     case XA_STRING:
  78.     *type = XA_STRING;
  79.     *value = (caddr_t)"Hello world!";
  80.     *length = XtStrlen(*value);
  81.     *format = 8;
  82.     return True;
  83.     
  84.     default:
  85.     return False;
  86.     }
  87. }
  88.  
  89. /* ARGSUSED */
  90. void LoseSelection(w, selection)
  91.     Widget w;
  92.     Atom *selection;
  93. {
  94.  
  95.     /*fprintf(stderr, "Lost Selection\n");*/
  96. }
  97.  
  98. /* ARGSUSED */
  99. void SelectionDone(w, selection, target)
  100.     Widget w;
  101.     Atom *selection, *target;
  102. {
  103. /*  
  104.     ScaleWidget sw = (ScaleWidget) w;
  105.     if (*target != XA_TARGETS)
  106.     XtFree(sw->scale.value);
  107. */
  108. }
  109.  
  110. void SWGrabSelection(w, time)
  111.     Widget w;
  112.     Time time;
  113. {
  114.     
  115.     if (XtOwnSelection(w, XA_PRIMARY, time,
  116.                ConvertSelection, LoseSelection, SelectionDone))
  117.  
  118.         /*fprintf(stderr, "Own the selection\n")*/;
  119. }
  120.  
  121. /* ARGSUSED */
  122. void SelectionCallback(w, clientData, selection, type, v, length, format)
  123.     Widget w;
  124.     XtPointer clientData; 
  125.     Atom *selection, *type;
  126.     XtPointer v;
  127.     unsigned long *length;
  128.     int *format;
  129. {
  130.     caddr_t value = (caddr_t)v;
  131.     Pixmap *pixmap;
  132.     XImage *image;
  133.     Window root;
  134.     int x, y;
  135.     unsigned int width, height, border_width, depth;
  136.  
  137.     switch (*type) {
  138.     
  139.     case XA_PIXMAP:
  140.     pixmap = (Pixmap *) value;
  141.     XGetGeometry(XtDisplay(w), *pixmap, &root, &x, &y,
  142.              &width, &height, &border_width, &depth);
  143.     image = XGetImage(XtDisplay(w), *pixmap, 0, 0, width, height, 
  144.               AllPlanes, ZPixmap);
  145.     SWAutoscale(w);
  146.     SWSetImage(w, image);
  147.     XFree((char *)pixmap);
  148.     XDestroyImage(image);
  149.     break;
  150.     
  151.     case XA_STRING:
  152.         /*fprintf(stderr, "Received:%s\n", value);*/
  153.     break;
  154.  
  155.     default:
  156.     XtWarning(" selection request failed.  ScaleWidget");
  157.     break;
  158.     }
  159. }
  160.  
  161. void SWRequestSelection(w, time)
  162.     Widget w;
  163.     Time time;
  164. {
  165.     /*fprintf(stderr, "------------------------------------------>\n");*/
  166.     XtGetSelectionValue(w, XA_PRIMARY, XA_PIXMAP,
  167.             SelectionCallback, NULL, time);
  168. }
  169.  
  170.